#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int calculate(int a, int b, string c)
    {
        if (c == "+")
            return a + b;
        if (c == "-")
            return a - b;
        if (c == "*")
            return a * b;
        if (c == "/")
            return a / b;
        return -1;
    }
    int evalRPN(vector<string>& tokens) {
        stack<int> stk;
        int n = tokens.size();
        for (int i = 0; i < n; i++)
        {
            if (tokens[i] == "+" || tokens[i] == "-" || tokens[i] == "*" || tokens[i] == "/")
            {
                int a = stk.top(); stk.pop();
                int b = stk.top(); stk.pop();
                int c = calculate(b, a, tokens[i]);
                stk.push(c);
            }
            else
                stk.push(atoi(tokens[i].c_str()));
        }
        return stk.top();
    }
};